/**求购商品列表页面 */
//未完成：分页，没有数据，下拉加载，加载完成。。。
var basePage = require('../../../../common/BasePage');
var baseList = require('../../../../common/BaseList');
Page({
    behaviors: [basePage, baseList],
    data: {
        search: '',
        reqUrl: "/home/product/items",
        searchId: 0,
        /**页面类型 */
        typeArr: [{
                reqUrl: "/home/product/items",
                title: "选择商品",
                client: ''
            },
            {
                reqUrl: "/home/staff/express/user",
                title: "请选择用户",
                client: 'express'
            },
        ],
        /**0：搜索商品，1：搜索用户 */
        type: 0,
    },
    onLoad(data) {
        data.wh_id ? this.data.reqData.wh_id = data.wh_id : "";
        this.req_items();
    },
    /**
     * 请求产品列表
     */
    // login_reload(){
    //   this.request({
    //     url: this.data.host + '/home/product/items?so='+this.data.search
    //   }, this.get_pdc_ok); 
    // },
    init_val(val, index, arr) {
        val.select=false
        this.data.type == 0 ? val.thumb = this.get_thumb(val.product_img) : val.thumb = this.get_thumb(val.face);
        // console.log("val.thumb",val.thumb);
    },
    // get_pdc_ok(res){
    //     console.log("get_pdc_ok",res);
    //     res.data.map(val=>{
    //         val.thumb=this.get_thumb(val.product_img);
    //         // console.log("val.thumb",val.thumb);
    //       })
    //     this.setData({
    //         pdcArr:res.data,
    //     });
    // },
    search_change({
        detail
    }) {
        // console.log("search_change", detail);
        if (this.data.searchId) {
            clearTimeout(this.data.searchId);
        }
        this.data.searchId = setTimeout(() => {
            console.log("执行搜索");
            this.data.searchId = 0;
            this.data.reqData.so = detail;
            this.data.current_page = 0;
            this.req_items();

        }, 1000);

    },
    choosegoods(e) {
        // let {
        //     index
        // } = e.mark;
       
        

        let {index}=e.mark
        let itemArr=this.data.itemArr
        console.log("itemArr", e);
        itemArr[index].select=!itemArr[index].select
        this.setData({
            itemArr:itemArr
        })
    },
    submitBtn_click(){
        let itemArr=this.data.itemArr
        let goodsList=[]
        itemArr.map(val=>{
            if(val.select){
                goodsList.push(val)
            }
            
        })
        const eventChannel = this.getOpenerEventChannel()
        eventChannel.emit('choose_goods', goodsList);
        wx.navigateBack({
            delta: 1,
        })
    }
})